package it.afs.worklog.application.form;

import java.util.List;

import it.afs.worklog.Commessa;

import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.IModel;

public class CommessaDropDownChoice extends DropDownChoice<Commessa>
{
	private static final long serialVersionUID = -2252612539817795747L;
	
	private boolean showDisabled;

	public CommessaDropDownChoice(String id, IModel<? extends List<? extends Commessa>> choices) {
		super(id, choices);
	}

	public CommessaDropDownChoice(String id, IModel<Commessa> model, List<? extends Commessa> choices) {
		super(id, model, choices);
	}
	
	public CommessaDropDownChoice(String id, IModel<Commessa> model, IModel<? extends List<? extends Commessa>> choices) {
		super(id, model, choices);
	}

	@Override
	protected void onConfigure() {
		setChoiceRenderer(new CommessaChoiceRenderer());
		super.onConfigure();
	}
	
	@Override
	protected boolean isDisabled(Commessa object, int index, String selected)
	{
		return !object.getAttivo() && !showDisabled;
	}
	
	public void setShowDisabled(boolean showDisabled) {
		this.showDisabled = showDisabled;
	}

	public boolean isShowDisabled() {
		return showDisabled;
	}

	private class CommessaChoiceRenderer implements IChoiceRenderer<Commessa>
	{
		private static final long serialVersionUID = -746352479383873144L;

		@Override
		public Object getDisplayValue(Commessa object) {
			return object.getTitolo();
		}

		@Override
		public String getIdValue(Commessa object, int index) {
			return String.valueOf(index);
		}
	}
}